package huang.teamwork12;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class SellerControl {
			//商店的用户，可以添加商品到商店。
			public boolean addGoods(Goods goods){
				boolean result=false;
				BaseDao bd=new BaseDao();
				Connection con=bd.getCon();
				String sql="insert into goods (name,price,amount) values(?,?,?)";
				try {
					PreparedStatement ps =con.prepareStatement(sql);
					ps.setDouble(3, goods.getPrice());
					ps.setInt(2, goods.getAmount());
					ps.setString(1, goods.getName());
					result=ps.execute();
					System.out.println("添加成功！！！");
					if(ps!=null){
						ps.close();
					}
					if(con!=null){
						con.close();
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return result;
			}
	
	
	
			//店主可以修改，商品的价格，数量，名字
			public boolean modifyGoods(Goods goods){
				boolean result=false;
				BaseDao bd=new BaseDao();
				Connection con=bd.getCon();
				String sql="update goods set price=?,amount=? where name=?";
				try {
					PreparedStatement ps =con.prepareStatement(sql);
					ps.setDouble(1, goods.getPrice());
					ps.setInt(2, goods.getAmount());
					ps.setString(3, goods.getName());
					result=ps.execute();
					System.out.println("修改成功！！！");
					if(ps!=null){
						ps.close();
					}
					if(con!=null){
						con.close();
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return result;
			}
}
